<template>
  <div id="app">
    <Header></Header>
    <!-- text -->
    <!-- 6 -->
    <router-view />

    <back-to-top></back-to-top>
    <player></player>
  </div>
</template>

<script>
import Header from '@/layout/Header.vue'
import Player from './layout/Player.vue'
import BackToTop from './components/common/backToTop.vue'

export default {
  components: {
    Header,
    Player,
    BackToTop
  },
  created() {
    const token = window.sessionStorage.getItem('token')
    if (token) {
      this.$store.commit('saveToken', token)
    }
    const cookie = window.sessionStorage.getItem('cookie')
    if (cookie) {
      this.$store.commit('setCookie', cookie)
    }
    const userDetail = JSON.parse(window.sessionStorage.getItem('userDetail'))
    if (userDetail) {
      this.$store.commit('saveUserDetail', userDetail)
    }

    const swiperImg = JSON.parse(window.localStorage.getItem('swiperImg'))
    if (swiperImg) {
      this.$store.commit('savaSwiperImg', swiperImg)
    }
    //在页面加载时读取sessionStorage里的状态信息
    // if (sessionStorage.getItem('store')) {
    //   this.$store.replaceState(
    //     Object.assign(
    //       {},
    //       this.$store.state,
    //       JSON.parse(sessionStorage.getItem('store'))
    //     )
    //   )
    // }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    //   window.addEventListener('beforeunload', () => {
    //     sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    //   })
  }
}
</script>

<style lang="scss"></style>
